﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SvgToDxfConverter
{
    public partial class SvgToDxfForm: Form
    {
        public SvgToDxfForm()
        {
            InitializeComponent();
        }

        private void SvgToDxfForm_Load(object sender, EventArgs e)
        {

        }
 

        private void button1_Click(object sender, EventArgs e)
        {// 创建 OpenFileDialog
            OpenFileDialog openFileDialog = new OpenFileDialog();

            // 设置对话框属性
            openFileDialog.Title = "选择SVG文件";
            openFileDialog.Filter = "SVG图像文件 (*.svg)|*.svg|所有文件 (*.*)|*.*"; // 只显示.svg文件
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            // 关键：ShowDialog(this) 确保对话框居中于父窗体
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string selectedFile = openFileDialog.FileName;

                // 额外检查文件扩展名（防止用户手动输入非.svg文件）
                if (!selectedFile.EndsWith(".svg", StringComparison.OrdinalIgnoreCase))
                {
                    MessageBox.Show("请选择.svg格式的文件！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    textBox1.Text = selectedFile; // 显示到文本框
                   
                }
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            // 创建 FolderBrowserDialog
            using (FolderBrowserDialog folderDialog = new FolderBrowserDialog())
            {
                folderDialog.Description = "请选择文件夹"; // 对话框标题
                folderDialog.RootFolder = Environment.SpecialFolder.MyComputer; // 初始根目录
                folderDialog.ShowNewFolderButton = true; // 允许新建文件夹

                // 显示对话框并获取结果
                if (folderDialog.ShowDialog(this) == DialogResult.OK)
                {
                    string selectedFolder = folderDialog.SelectedPath;
                    textBox2.Text = selectedFolder; // 显示到文本框

                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SvgToDxf svgToDxf=   new SvgToDxf();
            string svgFileName=Path.GetFileNameWithoutExtension(textBox1.Text);
            string uniqueFilePath = FileHelper.GetUniqueFileName(textBox2.Text, svgFileName + ".dxf");
            svgToDxf.Convert(textBox1.Text, uniqueFilePath);
            MessageBox.Show("DXF file created: " + uniqueFilePath);
        }
    }
}
